//
//  HJPhotoOrVideoLeftMsgCell.m
//  project
//
//  Created by hu on 2019/3/27.
//  Copyright © 2019 健健. All rights reserved.
//

#import "HJPhotoOrVideoLeftMsgCell.h"

@interface HJPhotoOrVideoLeftMsgCell ()

/*
 * 头像父视图
 */
@property (weak, nonatomic) IBOutlet UIView *headSubView;
/*
 * 头像图片
 */
@property (weak, nonatomic) IBOutlet UIImageView *headImage;
/*
 * 内容图片
 */
@property (weak, nonatomic) IBOutlet UIImageView *contenImage;
/*
 * 播放按钮
 */
@property (weak, nonatomic) IBOutlet UIButton *playBtn;

@property (weak, nonatomic) IBOutlet UIButton *sendError;

@end

@implementation HJPhotoOrVideoLeftMsgCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    // 用户图片 圆角
    [self.headImage rounded:(UIRectCornerAllCorners) radius:20];
    // 图片外的圆环
    [self.headSubView rounded:(UIRectCornerAllCorners) radius:20 borderColor:[UIColor blackColor] borderWidth:1];
    [self.contenImage rounded:(UIRectCornerTopRight | UIRectCornerBottomLeft |UIRectCornerBottomRight) radius:18.5];
    self.contenImage.contentMode = UIViewContentModeScaleAspectFill;
    UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc]init];
    @weakify(self)
    [[tap rac_gestureSignal]subscribeNext:^(__kindof UIGestureRecognizer * _Nullable x) {
        @strongify(self)
        if (self.didLeftSelecteImageBrowser) {
            self.didLeftSelecteImageBrowser(self.contenImage);
        }
    }];
    self.contenImage.userInteractionEnabled = YES;
    [self.contenImage addGestureRecognizer:tap];
}
/*
 * 播放按钮点击事件
 */
- (IBAction)playBtnClicked:(id)sender {
    
    
}

// 发送失败
- (IBAction)sendErrorBtnClicked:(UIButton *)sender {
}

-(void)loadLeftImageOrVideoWitMsg:(RCMessage *)msg Avatar:(NSString *)url {
    
    if ([msg.content isMemberOfClass:[RCImageMessage class]]) {
        self.playBtn.hidden = YES;
        RCImageMessage *imageMsg = (RCImageMessage *)msg.content;
        //imageMsg.senderUserInfo
        
        [self.contenImage sd_setImageWithURL:[NSURL URLWithString:imageMsg.imageUrl] placeholderImage:setImage(@"img_mydongtai_defualt_avatar")];
        [self.headImage sd_setImageWithURL:[NSURL URLWithString:url]];
       // [self.headImage sd_setImageWithURL:[NSURL URLWithString:imageMsg.senderUserInfo.portraitUri]];
    }else if ([msg.content isMemberOfClass:[RCSightMessage class]]) {
        self.playBtn.hidden = NO;
        RCSightMessage *sightMsg = (RCSightMessage *)msg.content;
        self.contenImage.image = sightMsg.thumbnailImage;
        [self.headImage sd_setImageWithURL:[NSURL URLWithString:sightMsg.senderUserInfo.portraitUri]];
    }
}
-(void)loadLeftImageOrVideoWitMsg:(RCMessage *)msg {
    if ([msg.content isMemberOfClass:[RCImageMessage class]]) {
        self.playBtn.hidden = YES;
        RCImageMessage *imageMsg = (RCImageMessage *)msg.content;
        //imageMsg.senderUserInfo
        [self.contenImage sd_setImageWithURL:[NSURL URLWithString:imageMsg.imageUrl] placeholderImage:setImage(@"img_mydongtai_defualt_avatar")];
        //[self.headImage sd_setImageWithURL:[NSURL URLWithString:url]];
        [self.headImage sd_setImageWithURL:[NSURL URLWithString:imageMsg.senderUserInfo.portraitUri]];
    }else if ([msg.content isMemberOfClass:[RCSightMessage class]]) {
        self.playBtn.hidden = NO;
        RCSightMessage *sightMsg = (RCSightMessage *)msg.content;
        self.contenImage.image = sightMsg.thumbnailImage;
        [self.headImage sd_setImageWithURL:[NSURL URLWithString:sightMsg.senderUserInfo.portraitUri]];
    }
    
    
}
@end
